#!/usr/bin/ruby

def replace_in_file(filename, s, r)
    lines = []
    File.open(filename, "r"){|f| lines = f.readlines }
    lines = lines.inject([]){|l, line| l << line.gsub(s, r)}
    File.open(filename, "w"){|f| f.write(lines) }
end

def traverse_dir(file_path, regexp)
    file_list = Array.new
    if File.directory? file_path
        Dir.foreach(file_path) do |file|
            if file!="." and file!=".."
                traverse_dir(file_path+"/"+file, regexp)
            end
        end
    else
        if not file_path.include? regexp
            file_list.push(file_path)
        end
    end
    puts file_list

end

def replace_dir(file_path, regexp)
    file_list = Array.new
    if File.directory? file_path
        Dir.foreach(file_path) do |file|
            if file!="." and file!=".."
                replace_dir(file_path+"/"+file, regexp)
            end
        end
    else
        if not file_path.include? regexp
            replace_in_file(file_path, /xxx/, "svn")
        end
    end
end

replace_dir(".", "svn")


